from pathlib import  Path

if __name__ == '__main__':
    dir_str = '/home/chengyu/wallpapers/paper_one/'
    dir_p = Path(dir_str)

    if not dir_p.exists() or dir_p.is_file():
        print('此路径不存在')

    for child in dir_p.iterdir():
        c_name = child.name
        new_name = c_name.replace(" ", "")
        new_name = dir_str + new_name
        child.rename(new_name)

    print('修改文件名成功')
    exit(0)
